import java.io.IOException;
import java.net.SocketException;
import java.util.HashMap;
import java.util.Map;

public class Demo_UdpDictServer extends Demo_UdpEchoServer{
    //创建一个哈希表，表示字典
    Map<String, String> dict = new HashMap<>();
    public Demo_UdpDictServer(int port) throws SocketException {
        super(port);
        dict.put("cat", "猫咪");
        dict.put("dog", "狗子");
        dict.put("pig", "八戒");
    }

    @Override
    public String process(String request) {
        return dict.getOrDefault(request, "未找到该词汇");
    }

    public static void main(String[] args) throws IOException {
        Demo_UdpDictServer dictServer = new Demo_UdpDictServer(9999);
        dictServer.start();
    }
}
